﻿using Application.CodeRuleService;
using AutoMapper;
using Domain.Entity;
using Domain.Entity.sys;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.BusinessTypeService
{
    public class BusinessTypeService : IBusinessTypeService
    {
        private readonly IBusinessTypeRepository businessTypeRepository;
        private readonly IMapper mapper;

        public BusinessTypeService(IBusinessTypeRepository businessTypeRepository, IMapper mapper)
        {
            this.businessTypeRepository = businessTypeRepository;
            this.mapper = mapper;
        }

        //添加业务类型信息
        public async Task<int> AddBusinessType(AddBusinessTypeDto addBusinessTypeDto)
        {
            //转换
            BusinessType businessType = mapper.Map<BusinessType>(addBusinessTypeDto);
            return await businessTypeRepository.AddBusinessType(businessType);
        }

        //删除业务类型信息
        public async Task<int> DeleteBusinessType(int id)
        {
            return await businessTypeRepository.DeleteBusinessType(id);
        }

        //分页查询业务类型信息
        public async Task<FenYe<BusinessType>> GetBusinessType(FenYe<BusinessType> fenYe, string? typename, int? status, string? field, string? createname)
        {
            return await businessTypeRepository.GetBusinessType(fenYe, typename, status, field, createname);
        }

        //根据id查询业务类型信息
        public async Task<BusinessType> GetBusinessTypeById(int id)
        {
            return await businessTypeRepository.GetBusinessTypeById(id);
        }


        //根据方向查询业务类型
        public async Task<List<BusinessType>> GetBusinessTypes(string field)
        {
            return await businessTypeRepository.GetBusinessTypes(field);
        }

        //修改业务类型信息
        public async Task<int> UpdateBusinessType(UpdateBusinessTypeDto updateBusinessTypeDto)
        {
            //转换
            BusinessType businessType = mapper.Map<BusinessType>(updateBusinessTypeDto);
            return await businessTypeRepository.UpdateBusinessType(businessType);
        }
    }
}
